Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ResUtil = undefined;
var LogManager = require("AA_LogManager");
var ResKeeper = require("AA_ResKeeper");
var ResUtil = function () {
  function _creator() {}
  _creator.getResKeeper = function (t, o) {
    if (t) {
      return t.getComponent(ResKeeper.default) || (o ? t.addComponent(ResKeeper.default) : _creator.getResKeeper(t.parent, o));
    } else {
      return null;
    }
  };
  _creator.assignWith = function (t, o, i) {
    var a = _creator.getResKeeper(o, i);
    if (a && t) {
      a.autoReleaseRes(t);
      return t;
    } else {
      LogManager.LogMgr.error("AssignWith " + t + " to " + o + " faile");
      return null;
    }
  };
  _creator.instantiate = function (t) {
    var o = cc.instantiate(t);
    var i = _creator.getResKeeper(o, true);
    if (i) {
      var a = o._prefab;
      if (a) {
        var r = a.asset;
        i.autoReleaseRes(r);
      } else {
        LogManager.LogMgr.warn("instantiate " + t + ", autoRelease failed, not found asset");
      }
    } else {
      LogManager.LogMgr.warn("instantiate " + t + ", autoRelease failed, not found ResKeeper");
    }
    return o;
  };
  _creator.removeAllChildren = function (e, t) {
    undefined === t && (t = true);
    if (t) {
      var o = e.getComponentsInChildren(ResKeeper.default);
      for (var n = 0; n < o.length; n++) {
        o[n].node.destroy();
      }
    }
    e.removeAllChildren(t);
  };
  _creator.removeFromParent = function (e, t) {
    undefined === t && (t = true);
    if (t) {
      var o = e.getComponentsInChildren(ResKeeper.default);
      for (var n = 0; n < o.length; n++) {
        o[n].node.destroy();
      }
    }
    e.removeFromParent(t);
  };
  return _creator;
}();
exports.ResUtil = ResUtil;